package com.xauto.pioneer.appuser.model;

import android.content.Context;
import android.util.Log;

import net.tsz.afinal.FinalDb;
import net.tsz.afinal.annotation.sqlite.Id;
import net.tsz.afinal.annotation.sqlite.Table;

import org.json.JSONObject;

/**
 * 版本对象
 * Created by Lemon on 19/04/2017.
 */
@Table(name = "table_client_version")
public class ClientVersion extends BaseModel<ClientVersion> {

    /** 有更新(1-是/0-否)*/
    public String has_update;
    /** 强制更新(1-是/0-否)*/
    public String need_update;
    /** 更新提示(1-是/0-否)*/
    public String is_tips;
    /** 更新文字提示*/
    public String tips_content;
    /** 更新类型(1-web/2-apk ipa)*/
    public String download_type;
    /** 更新地址*/
    @Id(column = "download_url")
    public String download_url;

    public String getHas_update() {
        return has_update;
    }

    public void setHas_update(String has_update) {
        this.has_update = has_update;
    }

    public String getNeed_update() {
        return need_update;
    }

    public void setNeed_update(String need_update) {
        this.need_update = need_update;
    }

    public String getIs_tips() {
        return is_tips;
    }

    public void setIs_tips(String is_tips) {
        this.is_tips = is_tips;
    }

    public String getTips_content() {
        return tips_content;
    }

    public void setTips_content(String tips_content) {
        this.tips_content = tips_content;
    }

    public String getDownload_type() {
        return download_type;
    }

    public void setDownload_type(String download_type) {
        this.download_type = download_type;
    }

    public String getDownload_url() {
        return download_url;
    }

    public void setDownload_url(String download_url) {
        this.download_url = download_url;
    }

    @Override
    public ClientVersion parse(JSONObject jsonObject) {
        if(jsonObject != null) {
            has_update = jsonObject.optString("has_update");
            need_update = jsonObject.optString("need_update");
            is_tips = jsonObject.optString("is_tips");
            tips_content = jsonObject.optString("tips_content");
            download_type = jsonObject.optString("download_type");
            download_url = jsonObject.optString("download_url");
            return this;
        }
        return null;
    }

//    @Override
//    public boolean equals(Object o) {
//        if (((ClientVersion)o).contact_number.equals(contact_number)){
//            return true;
//        }
//        return false;
//    }

    public void saveDb(Context mContext, ClientVersion region) {
        FinalDb finalDb = FinalDb.create(mContext);
        finalDb.delete(region);
//        finalDb.deleteByWhere(ClientVersion.class, "download_url = \""+region.download_url+"\"");
        finalDb.save(region);
    }
}
